package com.nhncorp.pleiades.protocol;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;


import com.nhncorp.pleiades.client.LockService;
import com.nhncorp.pleiades.hadoop.Writable;
import com.nhncorp.pleiades.hadoop.WritableUtils;

public class LockMetaData implements Writable {
  
  private String creator;
  private String lockId;
  private int lockMode;
  private long generationNumber;
  private String contentKey;
  
  public LockMetaData() {
    new LockMetaData("ID");
  }
  
  public LockMetaData(String path) {
    this.creator = "NA";
    this.lockId = path;
    this.lockMode = LockService.LockMode.LOCK_SHARED.ordinal();
    this.generationNumber = System.nanoTime();
    this.contentKey = "KEY";
  }
  
  public void readFields(DataInput in) throws IOException {    
    creator = WritableUtils.readString(in);
    lockId = WritableUtils.readString(in);
    lockMode = in.readInt();
    generationNumber = in.readLong();
    contentKey = WritableUtils.readString(in);
  }

  public void write(DataOutput out) throws IOException {
    WritableUtils.writeString(out, creator);
    WritableUtils.writeString(out, lockId);
    out.writeInt(lockMode);
    out.writeLong(generationNumber);
    WritableUtils.writeString(out, contentKey);
  }  
  
  public String toString() {
    return creator + "," +lockId + "," + contentKey;
  }

  public String getContentKey() {
    return contentKey;
  }

  public void setContentKey(String contentKey) {
    this.contentKey = contentKey;
  }

  public String getCreator() {
    return creator;
  }

  public void setCreator(String creator) {
    this.creator = creator;
  }

  public long getGenerationNumber() {
    return generationNumber;
  }

  public void setGenerationNumber(long generationNumber) {
    this.generationNumber = generationNumber;
  }

  public String getLockId() {
    return lockId;
  }

  public void setLockId(String lockId) {
    this.lockId = lockId;
  }

  public int getLockMode() {
    return lockMode;
  }

  public void setLockMode(int lockMode) {
    this.lockMode = lockMode;
  }
}
